package com.kolon.business.mngr.banner.controller;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.kolon.business.mngr.banner.dao.BannerDao;
import com.kolon.framework.interfaces.SimpleController;
import com.kolon.framework.util.ComUtil;
import com.kolon.framework.util.MsgUtil;

@Controller("com.kolon.business.mngr.banner.controller.BannerFileDownloadController")
public class BannerFileDownloadController implements SimpleController {

	@Resource(name="com.kolon.business.mngr.banner.dao.BannerDaoImpl")
	private BannerDao bannerDao;
	
	public ModelAndView controller(HttpServletRequest request,
		HttpServletResponse response) throws Exception {
		return null;
	}
	
	@SuppressWarnings("rawtypes")
	@RequestMapping(value="/business/mngr/banner/imgDownload.do")
	public ModelAndView iconDownload(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		
		Map<String, String> map = new HashMap<String, String>();
		// 파라미터
		String bnerNo = ComUtil.nullChk(request.getParameter("bnerNo"));
		// 파라미터 값 체크
		if ("".equals(bnerNo)) 
			return new ModelAndView("redirect:/business/mngr/banner/bannerList.do");
		map.put("bnerNo", bnerNo);
		// 정보 조회
		Map bnerMap = bannerDao.getMap(map);
		// 정보 체크
		if (bnerMap == null)
			return new ModelAndView("redirect:/business/mngr/banner/bannerList.do");
		// 리턴
		ModelAndView mv = new ModelAndView("downloadView");
		File downloadFile = new File(MsgUtil.getMessage("banner.path") 
				+ bnerMap.get("IMG_NM"));
		mv.addObject("downloadFile", downloadFile);
		mv.addObject("fileName", bnerMap.get("IMG_NM"));
		return mv;
	}

}

